﻿#region Using

using System;
using System.Data;
using System.Web.UI;
using RuleCode.Table;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using RuleCode.Controls;
#endregion

namespace map.search
{
    public partial class WebForm2 : Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                if (string.IsNullOrEmpty(Request.Params["id"]))
                {
                    Response.Redirect("area.aspx");
                }
                else
                {
                    Bind();
                }
            }
        }

        public string p1 = "";
        public string p2="";
        public string p3 = "";
        public BizArea biz;
        public BizAreaImages bizAreaImages;
        string id;
        private void Bind( )
        {
             id = Request.Params["id"];

            biz = BizArea.Find("RECID = " + id);
            Page.Title = biz.BizAreaName.ValueString;
            //BizAreaNameSpan.InnerHtml ="商圈 "+ biz.BizAreaName.Value+" 中的店铺";
            communityTitle.Text = biz.BizAreaName.Value;
            string bizimage = ((biz.BizAreaImagePath.ToString() != "") ? biz.BizAreaImagePath.ToString() : "../img/userdefaultimg.gif");
            Image22.ImageUrl = bizimage;
            p1 = biz.p1.ToString();
            p2 = biz.p2.ToString();
            p3 = biz.p3.ToString();
            //despLabel.Text = biz.BizAreaDescription.ToString();
            //transparentLabel.Text = biz.Description.ToString();
            DataTable dt;
            string sql = "";
            sql = " select distinct p1,p2 from vshop where areaRecid=" + id + " order by p1 desc ,p2 desc ";
            dt = RuleCode.Common.SqlHelper.Instance.ExecuteQuery(sql).Tables[0];
            DataList_all.DataSource = dt;
            DataList_all.DataBind();

            bizAreaImages = BizAreaImages.Find("BizAreaID='" + id + "'");
            this.DetailImgsDataList.DataSource = bizAreaImages.MyTable;
            this.DetailImgsDataList.DataBind();
            bindBroker();

        }
        private void bindBroker()
        {
            
            DataTable dt;
            string sql = "";
            sql = " select * from vshop where areaRecid=" + id + " and bokerstatus=2";
            dt = RuleCode.Common.SqlHelper.Instance.ExecuteQuery(sql).Tables[0];
            brokerList.DataSource = dt;
            brokerList.DataBind();

            bizAreaImages = BizAreaImages.Find("BizAreaID='" + id + "'");
            this.DetailImgsDataList.DataSource = bizAreaImages.MyTable;
            this.DetailImgsDataList.DataBind();
                    }

        protected void DataList_all_ItemDataBound(object sender, System.Web.UI.WebControls.DataListItemEventArgs e)
        {
            string id = Request.Params["id"];
            DataTable dt;
            string sql = "";
            if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
            {
                string _p1 = ((System.Data.DataRowView)e.Item.DataItem).Row.ItemArray[0].ToString();
                string _p2 = ((System.Data.DataRowView)e.Item.DataItem).Row.ItemArray[1].ToString();
                sql = " select * from vshop where p1 = '" + _p1 + "' and p2 = '" + _p2 + "' and "
                    + "areaRecid=" + id;
                dt = RuleCode.Common.SqlHelper.Instance.ExecuteQuery(sql).Tables[0];
                if (dt != null)
                {
                    DataList DataList_in = e.Item.FindControl("DataList_in") as DataList;
                    DataList_in.DataSource = dt;
                    DataList_in.DataBind();
                }
            }
        }

        protected string GetAreaTitle(string p1s, string p2s)
        {
            if (p2s == string.Empty && p1s == string.Empty)
            {
                return "未定义分区";
            }
            else
            {
                return p1s + p1 + " " + p2s + p2;
            }
        }
    }
}